#pragma once

#include <pthread.h>
#include <iostream>
#include "Mutex.hpp"
using namespace std;


namespace CondModule
{
    
    class Cond
    {
    public:
        Cond()
        {

            int n = pthread_cond_init(&_cond,nullptr);
        }
        //等待
        void wait(MutexModule::Mutex & _mutex)//不仅要等待，还要释放曾经的锁
        {
            //将锁释放
            pthread_cond_wait(&_cond,_mutex.LockPtr());
        }
        //唤醒一个
        void Nodify()
        {
            int n = pthread_cond_signal(&_cond);
        }
        //唤醒所有
        void NodifyAll()
        {
            int n = pthread_cond_broadcast(&_cond);
        }
        ~Cond()
        {
            pthread_cond_destroy(&_cond);
        }
    private:
        pthread_cond_t _cond;
    };
}